#include"stdio.h"
//changed
//number 24
int delay=6,destyear=0;

int odd_year( int year ){
	return ( year%400==0 || ( year%4==0 && year%100 != 0 ) );
}

int get_intial_delay( int iyear ){
	int ihead=iyear,itail=2011,total=0,flag=1,idelay=delay;
	if( iyear > 2011 )  {
		flag=0;
		itail=iyear;
		ihead=2011;
	}
	for( iyear=ihead; iyear <= itail; iyear++ ){
	if( odd_year( iyear ) ) total++;
	}
	total+=itail-ihead;
	total%=7;
	if(flag) { 
  		idelay -= total;
	        idelay = ( idelay + 7 ) % 7;
	}
	else {
	idelay += total;
	idelay %= 7;
	}
	return idelay;
}

int get_mouth_day(int xmou){
	int ndays=0;
	switch(xmou){
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12: ndays=31;break;
	case 4:
	case 6:
	case 9:
	case 11: ndays=30;break;
	case 2: {
				ndays=28;
			if( odd_year( destyear ) )
					ndays++;   	
				break;
			} 
	}
	return ndays;
}

int get_delay(int ymou){
	int i,temp=delay;
	for(i=1;i<ymou+1;i++){
	temp+=get_mouth_day(i);
	temp%=7;
	}
	return temp;
}

int pri_mouth(int xmou){
	int ndays=get_mouth_day(xmou),iday,idelay=delay; 
	printf("Sun Mon Tue Wen Tus Fri Sat\n");
	if( xmou != 1 ) idelay = get_delay ( xmou-1 );
	if( delay < 0 ) printf("%d delay overflow\n\n",delay);
	else 
		for( int i=0;i<idelay;i++ )printf("    ");                     //delay=0;delay--  arise a big problem ^_^
	for( iday=1; iday <= ndays; iday++ ){
		if( iday < 10 )printf(" %d  ",iday);
			else printf(" %d ",iday);
		if( ( iday + idelay) % 7 == 0 ) printf("\n");
	}
	return 0;
}

int main()
{
	int imou,ii,j;
	destyear=2011;
	delay=get_intial_delay( destyear ); 
//	printf(" %d\n\n ", delay ); 
//	for(j=0;j<7;j++){
//		delay=j;
	for(imou=1;imou<13;imou++){	
		printf("\t   %d\n\n",imou);
		pri_mouth(imou);
//	ii=get_delay(imou);
//	printf("%d\t",ii);
		printf("\n\n");
	}
//	printf("%d\t",get_delay(imou));}
		printf("\n\n");
//	}
	return 0;
}						//基本的功能都已经实现了，下一步只是找出任意一年的delay值，今天的函数编码比较给力，因为模块化的程度比较高，相互之间的交叉比较少，调用起来比较随意，还有就是小小的采用了一下增量式的开发，感觉到了这种一步一个脚印的强大稳定的开发方式是十分行之有效的，以后可以多多采用哈。想到的大概就这么多了，好了睡起。。。
